<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <%@include file="/WEB-INF/common/hplus-css.jsp"%>
</head>
<body class="gray-bg">
     <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox">
                    <div class="ibox-content">
                        <form action="${path}/user/saveeditpassword" class="form-horizontal m-t" id="userForm" method="post">
                            <input id="id" name="id" type="hidden" value="${id}">
                            
                             <div class="form-group">
                                <label class="col-sm-3 control-label">旧密码：</label>
                                <div class="col-sm-5">
                                    <input type="password" class="form-control" name="jiupassword" placeholder="请输入旧密码" />
                                	<span id="msg1"></span>
                                </div>
                            </div>
                           <div class="form-group">
                                <label class="col-sm-3 control-label">新密码：</label>
                                <div class="col-sm-5">
                                    <input type="password" class="form-control" name="password1" placeholder="请输入新密码" id="password1"/>
                                	<span id="msg2"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">确认密码：</label>
                                <div class="col-sm-5">
                                    <input type="password" class="form-control" name="password" placeholder="请再次输入新密码" id="password"/>
                                	<span id="msg3"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-3">
                                    <button class="btn btn-primary" id="update-btn" type="button">提交</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <%@include file="/WEB-INF/common/hplus-js.jsp"%>
    <script src="${path}/assets/hplus/js/demo/form-validate-demo.js"></script>
    <script>
 		//判断旧密码的值是否和本密码相同
        function showPwd(pwd){
        	  $.ajax({
	                url : "${path}/user/selpassword",
	                type : "post",
	                dataType : "json",
	                data : {"password":pwd.value},
	                success : function(json) {
	                    if(json.code != 0) {
	                    	pwd.focus();
	         				$("#msg1").html(json.msg).css("color","red");
	                    }else{
	                    	$("#msg1").html("");
	                    }
	                },
	                error : function(responseText) {
	                    showError("信息提交失败，请刷新重试");
	                }
	            }); 
 		}
        $(document).ready(function () {
        	$("#userForm").validate();
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
            
            $("#update-btn").click(function(){
            	var password1 = $("#password1").val();//新密码
	            var password = $("#password").val();//再次输入的新密码
	            if(password1 == ""){
	            	$("#msg2").html("*&nbsp;&nbsp;新密码不能为空").css("color","red");
	                return;
	            }
	            $("#msg2").html("");
	            if(password == ""){
	            	$("#msg3").html("*&nbsp;&nbsp;确认新密码不能为空").css("color","red");
	                return;
	            }
	            $("#msg3").html("");
	            if(password != password1){
	            	$("#msg3").html("*&nbsp;&nbsp;确认新密码跟新密码不相同").css("color","red");
	                return;
	            }
	            $("#msg3").html("");
            	var valid = $("#userForm").valid();
            	if(valid){
            		$("#userForm").ajaxSubmit({
                        dataType: "json",
                        success: function (json) {
                            var code = json.code;
                            if(code == 0){
                            	layer.msg(json.msg, {icon: 1});
                            	 setTimeout(function(){
                                 	window.location.reload();
                                 }, 1000);
                            }else{
                            	layer.msg(json.msg, {icon: 5});
                            }
                        },
                        error:function(){
                        	layer.msg('修改发生错误', {icon: 5});
                        }
                    });
            	}
            });
        });
    </script>
</body>
</html>
